﻿<Window x:Class="DSSDataServiceGenerator.Dialogs.ConnectWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local.Model="clr-namespace:DSSDataServiceGenerator.Model"
        xmlns:local.ViewModel="clr-namespace:DSSDataServiceGenerator.ViewModel"
        Title="Importing Metadata..."
        Height="340"
        Width="450"
        ResizeMode="NoResize"
        WindowStyle="SingleBorderWindow"
        WindowStartupLocation="CenterScreen"
        Content="{Binding ConnectionViewModel, RelativeSource={RelativeSource Self}}">
    <Window.Resources>
        <Style TargetType="Button">
            <Setter Property="Width"
                    Value="80" />
            <Setter Property="Padding"
                    Value="8" />
        </Style>
    </Window.Resources>
    <Window.ContentTemplate>
        <DataTemplate DataType="local.ViewModel:ConnectionViewModel">
            <Grid Margin="8">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="110" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock Text="Connection Type: " />
                <ComboBox Grid.Column="1"
                          SelectedItem="{Binding SelectedConnection}">
                    <ComboBox.ItemsSource>
                        <CompositeCollection>
                            <ComboBoxItem Content="&lt;Please Select&gt;"
                                          FontStyle="Italic" />
                            <CollectionContainer>
                                <CollectionContainer.Collection>
                                    <local.ViewModel:CollectionOfConnection />
                                </CollectionContainer.Collection>
                            </CollectionContainer>
                        </CompositeCollection>
                    </ComboBox.ItemsSource>
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ConnectionType}" />
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <ContentControl Grid.ColumnSpan="2"
                                Grid.Row="1"
                                Content="{Binding SelectedConnection}"
                                VerticalAlignment="Top"
                                Margin="0,4,0,0">
                    <ContentControl.Resources>
                        <DataTemplate DataType="{x:Type local.Model:SqlConnection}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="110" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <TextBlock Text="Server:" />
                                <TextBox Grid.Column="1"
                                         Text="{Binding Server}" />

                                <TextBlock Grid.Row="1"
                                           Text="Port:" />
                                <TextBox Grid.Row="1"
                                         Grid.Column="1"
                                         Text="{Binding Port}" />

                                <TextBlock Grid.Row="2"
                                           Text="User Id:" />
                                <TextBox Grid.Row="2"
                                         Grid.Column="1"
                                         Text="{Binding Username}" />

                                <TextBlock Grid.Row="3"
                                           Text="Password:" />
                                <TextBox Grid.Row="3"
                                         Grid.Column="1"
                                         Text="{Binding Password}" />

                                <TextBlock Grid.Row="4"
                                           Text="Database:" />
                                <TextBox Grid.Row="4"
                                         Grid.Column="1"
                                         Text="{Binding Database}" />

                            </Grid>
                        </DataTemplate>
                        <DataTemplate DataType="{x:Type local.Model:PostgreSqlConnection}">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="110" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <TextBlock Text="Server:" />
                                <TextBox Grid.Column="1"
                                         Text="{Binding Server}" />

                                <TextBlock Grid.Row="1"
                                           Text="Port:" />
                                <TextBox Grid.Row="1"
                                         Grid.Column="1"
                                         Text="{Binding Port}" />

                                <TextBlock Grid.Row="2"
                                           Text="User Id:" />
                                <TextBox Grid.Row="2"
                                         Grid.Column="1"
                                         Text="{Binding Username}" />

                                <TextBlock Grid.Row="3"
                                           Text="Password:" />
                                <TextBox Grid.Row="3"
                                         Grid.Column="1"
                                         Text="{Binding Password}" />

                                <TextBlock Grid.Row="4"
                                           Text="Database:" />
                                <TextBox Grid.Row="4"
                                         Grid.Column="1"
                                         Text="{Binding Database}" />

                                <TextBlock Grid.Row="5"
                                           Text="Enlist: " />
                                <CheckBox Grid.Row="5"
                                          Grid.Column="1"
                                          IsChecked="{Binding Enlist}" />

                            </Grid>
                        </DataTemplate>
                    </ContentControl.Resources>
                </ContentControl>
                <StackPanel Orientation="Horizontal"
                            Grid.Row="2"
                            Grid.ColumnSpan="2"
                            VerticalAlignment="Bottom"
                            HorizontalAlignment="Right">
                    <Button Content="Connect"
                            Command="{Binding ConnectCommand}"
                            CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}" />
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Window.ContentTemplate>
</Window>
